package com.xiongwei.thread;

import com.xiongwei.pojo.User;

/**
 * to do
 *
 * @author XiongWei
 * @date 2021/1/15
 */
public class ThreadLocalUse {

    public static void main(String[] args) {

    }

    public void process(User user) {
        try {
            userThreadLocal.set(user);
            checkPermission();
            doWork();
            saveStatus();
            sendResponse();
        } finally {
            userThreadLocal.remove();
        }


    }

    static ThreadLocal<User> userThreadLocal = new ThreadLocal<>();

    private void sendResponse() {

    }

    private void saveStatus() {
    }

    private void doWork() {
    }

    private void checkPermission() {
        User user = userThreadLocal.get();
        log();
    }

    static void log() {
        System.out.println(Thread.currentThread().getName());
    }
}
